<template>
	<el-drawer v-model="isShowDrawer" direction="rtl" :before-close="handleClose" :size="curDrawerSize" :close-on-click-modal="isReadOnly">
		<template #header="{ titleId, titleClass }">
			<div class="zs-drawer-header" :id="titleId" :class="titleClass">
				<i class="icon-b-item zs-icon zs-text-blue zs-space-right-sm"></i>
				<div class="zs-title zs-text-black">{{ currentRow?.reportName }}</div>
			</div>
		</template>

		<template #default>
			<el-container class="zs-drawer-container">
				<el-scrollbar class="zs-drawer-content">
					<div class="zs-card" id="settlementReport-fundBalanceAnalysis-drawer-01">
						<el-input v-model="remark" :rows="30" type="textarea" placeholder=" " :disabled="isReadOnly" :maxlength="3000" show-word-limit />
					</div>
				</el-scrollbar>
				<hsDocWrapper :nodeList="curNodeList"></hsDocWrapper>
			</el-container>
		</template>

		<template v-if="handleType != 'info'" #footer>
			<el-button class="zs-btn-md zs-btn-primary" @click="doConfirm">提交</el-button>
		</template>
	</el-drawer>
</template>

<script setup>
	import { ref, watch, nextTick } from 'vue';
	import { useStore } from 'vuex';
	import { ElMessage } from 'element-plus';
	import { saveOrUpdateCommonSingleTextAnalysisApi, getCommonSingleTextAnalysisApi } from '@/api/SpecialReport/settlementReport';
	const props = defineProps({
		isShow: { type: Boolean, default: false },
		isReadOnly: { type: Boolean, default: true },
		handleType: { type: String, default: '' },
		currentRow: { type: Object },
	});
	let store = useStore();
	const curDrawerSize = ref(store.state.uiDrawerSizeBig);
	const emit = defineEmits(['close']);
	let isShowDrawer = ref(props.isShow);
	const curNodeList = ref([{ name: '分析', id: 'settlementReport-fundBalanceAnalysis-drawer-01' }]);
	watch(
		() => props.isShow,
		newVal => {
			isShowDrawer.value = newVal;
			nextTick(() => {
				newVal && getInfo();
			});
		},
	);

	//数据源
	let remark = ref();
	const getInfo = async () => {
		let res = await getCommonSingleTextAnalysisApi(props.currentRow.id);
		if (res.data.code != 200) return;
		remark.value = res.data.data?.text || '';
	};

	//提交
	const doConfirm = async () => {
		if (!remark.value) {
			ElMessage({ message: '请填写内容！', type: 'warning' });
			return;
		}
		let res = await saveOrUpdateCommonSingleTextAnalysisApi({text: remark.value, reportDetailId: props.currentRow.id})
		if (res.data.code == 200) {
			ElMessage({ message: '提交成功', type: 'success'});
			isShowDrawer.value = false;
			emit('close', { isShow: false, isRefresh: true });
		}
	};

	//关闭抽屉
	const handleClose = done => {
		emit('close', { isShow: false });
		done();
	};
</script>
